﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI;

using DevExpress.Web.ASPxHeadline;

using LMD.Lib.DataClass;
using LMD.Constant;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

/// <summary>
/// Summary description for SLAManager
/// </summary>
public static class SLAManager
{
    public static String BuildEditor_SLAData()
    {    
        String sxOutput = String.Empty;

        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox( 
            KSLA.CUSTOMER_ID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, 
            "SelectCompany()");
        String sxOTFComboContact = CustomControls.Create_OTFComboBox(
            KSLA.CP_ID, KLOV.Generic.CONTACTPERSON, null, null, TextboxType.Empty, "-1", String.Empty);
        String sxDateControl = CustomControls.Create_TextBox(KSLA.DELIVERED_DATE, KControl.INPUT_ID,
            null, true, TextboxType.Date);
        Dictionary<String, String> dicMonths = new Dictionary<String, String>();
        dicMonths.Add("1", "January");
        dicMonths.Add("2", "February");
        dicMonths.Add("3", "March");
        dicMonths.Add("4", "April");
        dicMonths.Add("5", "May");
        dicMonths.Add("6", "June");
        dicMonths.Add("7", "July");
        dicMonths.Add("8", "August");
        dicMonths.Add("9", "September");
        dicMonths.Add("10", "October");
        dicMonths.Add("11", "November");
        dicMonths.Add("12", "December");
        String sxComboMonth = CustomControls.Create_ComboBox(KSLA.SLA_MONTH, KControl.INPUT_ID, dicMonths, null);
        String sxFileUpload = CustomControls.BuildEditor_FileUpload(KSLA.FILEUPLOAD, KFileHandler.SLA.SLA_FILE,
            null, KControl.INPUT_ID, TextboxType.DocumentUpload);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Contact Person", sxOTFComboContact);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("SLA Month", sxComboMonth);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KSLA.SLA_YEAR, KControl.INPUT_ID, 
            "SLA Year", null, TextboxType.Integer);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Delivered Date", sxDateControl);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("SLA File", sxFileUpload);
        sxOutput +=
            "<input type=\"button\" id=\"btn_SLANew\" class=\"btn\" style=\"float: right; margin-left: 5px;\"" +
            "onclick=\"SLA_New();\" value=\"SAVE\" />" +
            "<div id=\"load_SLANew\" style=\"float: right; padding-right: 10px;\">";


        return sxOutput;
    }
    public static String BuildEditor_SLAFilter()
    {
        String sxOutput = String.Empty;

        //String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
        //    KSLA.CUSTOMER_ID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, String.Empty, "SelectCompany()");
        //String sxOTFCAR = CustomControls.Create_OTFComboBox(KSLA.CARID,
        //    KLOV.Generic.ICPCAR, "", "", TextboxType.Empty, "-1", String.Empty);
        String sxOTFComboCustomer = CustomControls.Create_OTFComboBox(
            KSLA.CUSTOMER_ID, KLOV.CourtesyCall.COMPANYLIST, null, null, TextboxType.Empty, "-1", String.Empty);
        String sxOTFCAR = CustomControls.Create_OTFComboBox(KSLA.CARID,
            KLOV.Generic.ICPCAR, null, null, TextboxType.Empty, String.Empty, "SelectCAR()");
        String sxStart = CustomControls.Create_TextBox(KSLA.START, KControl.INPUT_ID,
            null, true, TextboxType.Date);
        String sxEnd = CustomControls.Create_TextBox(KSLA.END, KControl.INPUT_ID,
            null, true, TextboxType.Date);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("CAR", sxOTFCAR);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", sxOTFComboCustomer);
        //sxOutput += CustomControls.BuildFieldSet_PairedLabel("CAR", sxOTFCAR);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Start Periode", sxStart);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("End Periode", sxEnd);
        sxOutput +=
            "<dt>&nbsp;</dt><dd><input type=\"button\" id=\"btnFilter\" class=\"btn\"" +
            "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"Filter();\" value=\"FILTER\" />" +
                "<input type=\"button\" id=\"btnAll\" class=\"btn\"" +
                "style=\"margin-left: 5px; margin-right: 5px; width:100px;\"" +
                "onclick=\"All();\" value=\"SHOW ALL\" /></dd> ";
        return sxOutput;
    }
    public static String BuildFieldSet_SLAData(this SLAData slaData)
    {
        String sxOutput = String.Empty;

        String cpInfo = String.Empty;
        int icpID = -1;
        String isNewCP = String.Empty;;
        if (slaData.iContactPersonID > 0)
        {
            icpID = slaData.iContactPersonID;
            isNewCP = "N";
        }
        else
        {
            icpID = slaData.iNewContactPersonID;
            isNewCP = "Y";
        }

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Company Name", slaData.sxCompanyName);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Contact Person", slaData.sxContactPersonName+cpInfo);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("SLA Month", slaData.sxMonth);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("SLA Year", slaData.iYear.ToString());
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Delivered Date", 
            slaData.dtmDeliveredDate.ToString("dd-MMM-yyyy"));
        if (slaData.iFile_Upload_ID > 0)
        {
            String sxLinkAttachment = CustomControls.Create_LinkDiv(KSLA.FILEUPLOAD,
            "downloadFile('" + slaData.iFile_Upload_ID.ToString() + "');"
            , slaData.sxOriginalFilename);
            sxOutput += CustomControls.BuildFieldSet_PairedLabel("SLA File", sxLinkAttachment);
        }
        return sxOutput;
    }
}
